import time

from selenium.webdriver.common.by import By

from common.DriverTools import DriverTools
from page.HomePage import HomePage


class RegisterPage(object):
    # 初始化实例属性
    def __init__(self):
        self.driver=DriverTools.get_driver()
        # 用户名
        self.user=(By.ID,'username')
        # 验证码
        self.verify_code=(By.NAME,'verify_code')
        # 密码
        self.pwd=(By.ID,'password')
        # 确认密码
        self.pwd2=(By.ID,'password2')
        # 协议勾选框
        self.protocol=(By.ID,'checktxt')
        # 注册按钮
        self.reg_btn=(By.LINK_TEXT,'同意协议并注册')

    # 定义注册方法
    def register(self,user,code,pwd,pwd2):
        self.driver.find_element(*self.user).send_keys(user)
        self.driver.find_element(*self.verify_code).send_keys(code)
        self.driver.find_element(*self.pwd).send_keys(pwd)
        self.driver.find_element(*self.pwd2).send_keys(pwd2)
        checkbox=self.driver.find_element(*self.protocol)
        if checkbox.is_selected():
            pass
        else:
            checkbox.click()
        self.driver.find_element(*self.reg_btn).click()

if __name__ == '__main__':
    driver=DriverTools.get_driver()
    driver.get("http://hmshop-test.itheima.net/")
    # HomePage().goto_login_page()
    HomePage().goto_register_page()
    time.sleep(2)
    RegisterPage().register("13011112121",'8888','123456','123456')
    driver.quit()